﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PServiceBus.WebAPI.DTO;
using System.Web.Http;
using System.Net.Http;
using PServiceBus.Services.Gateway.Runtime;
using PServiceBus.Services.Web.DTO;

namespace PServiceBus.WebAPI.Controllers {
    public partial class ESBController {

        public IList<object> GetNextMessages([FromUri]StreamingInfo info) {
            return NextMessages(info);
        }

        [AcceptVerbs(GET)]
        public HttpResponseMessage GetCreateSubscriber([FromUri]string name) {
            if (name == null) throw new ArgumentNullException("name");
            MessageBus.CreateSubscriber(name);
            return EmptyResponse;
        }

        [AcceptVerbs(GET)]
        public HttpResponseMessage GetChangeSubscriberDurability([FromUri]SubscriptionInfo info) {
            return ChangeSubscriberDurability(info);
        }

        [AcceptVerbs(GET)]
        public string GetSubscribe([FromUri]SubscriptionInfo info) {
            return Subscribe(info);
        }

        [AcceptVerbs(GET)]
        public string GetUpdate([FromUri]SubscriptionInfo info) {
            return Update(info);
        }

        [AcceptVerbs(GET)]
        public string GetUnSubscribe([FromUri]SubscriptionInfo info) {
            return UnSubscribe(info);
        }

        [AcceptVerbs(GET)]
        public HttpResponseMessage GetAddTransport([FromUri]SubscriptionInfo info) {
            return AddTransport(info);
        }

        [AcceptVerbs(GET)]
        public HttpResponseMessage GetDeleteTransport([FromUri]SubscriptionInfo info) {
            return DeleteTransport(info);
        }

        [AcceptVerbs(GET)]
        public Subscriber GetSelectSubscriber([FromUri]string name) {
            if (name == null) throw new ArgumentNullException("info");
            return MessageBus.SelectSubscriber(name);
        }

        [AcceptVerbs(GET)]
        public Topic GetSelectTopic([FromUri]string name) {
            return MessageBus.SelectTopic(name);
        }

        [AcceptVerbs(GET)]
        public bool GetPing() {
            return Ping();
        }

        [AcceptVerbs(GET)]
        public HttpResponseMessage GetDeleteSubscriber([FromUri]string name) {
            if (name == null) throw new ArgumentNullException("name");
            MessageBus.DeleteSubscriber(name);
            return EmptyResponse;
        }

        [AcceptVerbs(GET)]
        public HttpResponseMessage GetDeleteTopic([FromUri]string name) {
            if (name == null) throw new ArgumentNullException("name");
            MessageBus.DeleteTopic(name);
            return EmptyResponse;
        }

        [AcceptVerbs(GET)]
        public HttpResponseMessage GetRegisterTopic([FromUri]TopicInfo info) {
            return RegisterTopic(info);
        }


        [AcceptVerbs(GET)]
        public HttpResponseMessage GetPublishTopic([FromUri]PublishTopicInfo info) {
            return PublishTopic(info);
        }

        [AcceptVerbs(GET)]
        public IEnumerable<Topic> GetGetTopics() {
            return MessageBus.GetTopics();
        }

        [AcceptVerbs(GET)]
        public HttpResponseMessage GetDisconnect(string name) {
            if (name == null) throw new ArgumentNullException("name");
            EndStreaming(name);
            MessageBus.Dispose();
            return EmptyResponse;
        }
    }
}
